package com.eastfair.enums;

import com.eastfair.annotation.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * <p>
 * 字段类型枚举类
 * 
 * </p>
 *
 * @author zjn
 * @date 2021-07-29
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "FieldTypeEnum", description = "字段类型 #{NUMBER:数字输入框;INPUT:文本框;PASSWORD:密码框" +
        ";TEXT_AREA:文本域;UPLOAD:文件上传;SELECT:单选框;SELECT_MULTIPLE:复选框;COLOR_PICKER:色值选择器;TIME_PICKER:时间选择器-枚举")
public enum FieldTypeEnum implements BaseEnum {

    /**
     * NUMBER="数字输入框"
     */
    NUMBER("数字输入框"),
    /**
     * INPUT="文本框"
     */
    INPUT("文本框"),
    /**
     * PASSWORD="密码框"
     */
    PASSWORD("密码框"),
    /**
     * TEXT_AREA="文本域"
     */
    TEXT_AREA("文本域"),
    /**
     * UPLOAD="文件上传"
     */
    UPLOAD("文件上传"),
    /**
     * SELECT="下拉框"
     */
    SELECT("下拉框"),
    /**
     * CASCADER="级联选择器"
     */
    CASCADER("级联选择器"),
    /**
     * COLOR_PICKER="色值选择器"
     */
    COLOR_PICKER("色值选择器"),
    /**
     * TIME_PICKER="时间选择器"
     */
    TIME_PICKER("时间选择器"),
    /**
     * TIME_PICKER="时间选择器"
     */
    WANG_EDITER("富文本"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static FieldTypeEnum match(String val, FieldTypeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static FieldTypeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(FieldTypeEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "NUMBER,INPUT,PASSWORD,TEXT_AREA,UPLOAD,SELECT,SELECT_MULTIPLE,COLOR_PICKER,TIME_PICKER", example = "NUMBER")
    public String getCode() {
        return this.name();
    }

}
